package com.trace.app.controller;


import com.trace.app.entity.Record;
import com.trace.app.entity.ResponseResult;
import com.trace.app.service.RecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Record)表控制层
 *
 * @author lionkliu
 * @since 2024-03-17 15:55:23
 */
@RestController
@RequestMapping("record")
public class RecordController {

    @Resource
    private RecordService recordService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return recordService.selectPage(pageNum, pageSize);
    }

    @GetMapping("{rawId}")
    public ResponseResult getRecordsByRawId(@PathVariable Integer rawId) {
        return recordService.getRecordsByProId(rawId);
    }

    @GetMapping("/user/{userId}")
    public ResponseResult getRecordsByUserId(@PathVariable Integer userId) {
        return recordService.getRecordsByUserId(userId);
    }

    @GetMapping("/search")
    public ResponseResult search(@RequestParam("pageNum") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize,
                                 @RequestParam(value = "userId", required = false) Integer userId,
                                 @RequestParam(value = "rawId", required = false) Integer rawId) {
        return recordService.search(pageNum, pageSize, userId, rawId);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Record record) {
        return recordService.insertOne(record);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Record record) {
        return recordService.updateOne(record);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return recordService.deleteById(id);
    }

}
